<?php

class HomeModel extends Model {
    function insert($field){
        $pict_url = null;

        mkdir("img/".$field['username'],0777);

        //save uploaded file
        if ($field["pp"]["error"] > 0){
            //do nothing
            //echo "sesuatu";
        }else{
            if (file_exists("img/" .$field['username'].'/'.$field["pp"]["name"])) {
                //echo $field["pp"]["name"] . " already exists. ";
            }
            else{
                move_uploaded_file($field["pp"]["tmp_name"],"img/" .$field['username'].'/'. $field["pp"]["name"]);
                //$pict_url = "img/".$field['username']."/". $field["pp"]["name"];
                $pict_url = 'img/'.$field['username'].'/'. $field['pp']['name'];
            }
        }
        //echo $pict_url;

        //do the query
        $insert_string = "'".$field['fullname']."','".$field['username']."','".$field['password']."','".$field['tgllahir']."','".$field['email']."','".$pict_url."','".$field['gender']."','".$field['kota'].",'1' '";
        $this->query('insert into user (Fullname,Username,Password,Tgllahir,Email,Pp,Gender,Kota,Status) values ('.$insert_string.')');
        //$myquery = "insert into user (Fullname,Username,Password,Tgllahir,Email,Pp,Gender,Kota) values (".$insert_string.")";
        //echo $myquery;
    }

    function insertwall($field) {
        $insert_string = "'".$field['iduser']."'";
        $this->query('insert into wall (Iduser) values ('.$insert_string.')');
    }

    function setLogin($id){
        $this->query('update user set status=\'1\' where iduser = '.$id.' ');
    }
}
